package com.wenwan.manage.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wenwan.manage.service.UserReceivingAddressService;

import javax.annotation.Resource;

/**
 * 用户-收货地址管理
 * 
 * @author Admin
 *
 */
@Controller
@RequestMapping(value = "/user/receiving/address")
public class UserReceivingAddressController {

	@Resource
	private UserReceivingAddressService userReceivingAddressService;

	@ResponseBody
	@RequestMapping(value = "/create", method = { RequestMethod.POST })
	public Map<String,Object> create(@RequestParam(required = true) String receiver,
			@RequestParam(required = true) String linkPhone, @RequestParam(required = true) String zone,
			@RequestParam(required = true) String street, @RequestParam(required = true) String detailedAddress,
			@RequestParam(required = true) String userId) {
		return userReceivingAddressService.create(receiver, linkPhone, zone, street, detailedAddress, userId);
	}

	@ResponseBody
	@RequestMapping(value = "/delete/by/id", method = { RequestMethod.POST })
	public Map<String,Object> deleteById(@RequestParam(required = true) String id) {
		return userReceivingAddressService.deleteById(id);
	}

	@ResponseBody
	@RequestMapping(value = "/update", method = { RequestMethod.POST })
	public Map<String,Object> update(@RequestParam(required = true) String id,
			@RequestParam(required = false) String receiver, @RequestParam(required = false) String linkPhone,
			@RequestParam(required = false) String zone, @RequestParam(required = false) String street,
			@RequestParam(required = false) String detailedAddress, @RequestParam(required = false) String userId) {
		return userReceivingAddressService.update(id, receiver, linkPhone, zone, street, detailedAddress, userId);
	}

	@ResponseBody
	@RequestMapping(value = "/select/by/user/id", method = { RequestMethod.GET })
	public Map<String,Object> selectByUserId(@RequestParam(required = true) String userId) {
		return userReceivingAddressService.selectByUserId(userId);
	}

	@ResponseBody
	@RequestMapping(value = "/select/one/by/id", method = { RequestMethod.GET })
	public Map<String,Object> selectOneById(@RequestParam(required = true) String id) {
		return userReceivingAddressService.selectOneById(id);
	}

}
